/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {
    struct ListNode* taila=headA; struct ListNode* tailb=headB;
    int longa=0,longb=0;
    while(taila->next)
    {
        taila=taila->next;
        longa++;
    }
    while(tailb->next)
    {
        tailb=tailb->next;
        longb++;
    }
    int gap=abs(longa-longb);
    struct ListNode* longlist=headA;
    struct ListNode* shortlist=headB;
    if(longa<longb)
    {
        longlist=headB;
        shortlist=headA;
    }
    while(gap--)
    {
        longlist=longlist->next;
    }
    while(longlist!=shortlist)
    {
        longlist=longlist->next;
        shortlist=shortlist->next;
    }
    return longlist;
}
